home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / CheeseToast 1.0.1 / Source / ObjectWindow.c < prev    next >
Text File  |  1993-08-17  |  3KB  |  126 lines

  1. /************************************************************************************
  2.  * ObjectWindow.c            - Jim Bumgardner            
  3.  *
  4.  * Pseudo-Object Oriented Stuff
  5.  ************************************************************************************/
  6. #include "ObjectWindow.h"
  7.  
  8. WindowPtr InitObjectWindow(short resID, ObjectWindowPtr theWindow, Boolean isFloating)
  9. {
  10.     WindowPtr wp;
  11.     if (theWindow == NULL) {
  12.         theWindow = (ObjectWindowPtr) NewPtrClear(sizeof(ObjectWindowRecord));
  13.         theWindow->ownStorage = true;
  14.     }
  15.     else
  16.         theWindow->ownStorage =false;
  17.     theWindow->floating = false;
  18.     wp = GetNewCWindow(resID, (WindowPtr) theWindow, (WindowPtr) -1L);
  19.     ((WindowPeek) wp)->refCon = MyWindowID;
  20.     theWindow->Update = DefaultUpdate;
  21.     theWindow->Activate = DefaultActivate;
  22.     theWindow->HandleClick = DefaultHandleClick;
  23.     theWindow->Dispose = DefaultDispose;
  24.     theWindow->Draw = DefaultDraw;
  25.     theWindow->Idle = NULL;
  26.  
  27.     ((ObjectWindowPtr) theWindow)->floating = isFloating;
  28.  
  29.     LocateWindows();
  30.     return wp;
  31. }
  32.  
  33. void DefaultDispose(WindowPtr theWin)
  34. {
  35.     CloseWindow(theWin);
  36.     if (((ObjectWindowPtr) theWin)->ownStorage)
  37.         DisposPtr((Ptr) theWin);
  38. }
  39.  
  40. void DefaultUpdate(WindowPtr theWin)
  41. {
  42.     GrafPtr    savePort;
  43.     GetPort(&savePort);
  44.     SetPort(theWin);
  45.     BeginUpdate(theWin);
  46.     ((ObjectWindowPtr) theWin)->Draw(theWin);
  47.     EndUpdate(theWin);
  48.     SetPort(savePort);
  49. }
  50.  
  51. void DefaultActivate(WindowPtr theWin)
  52. {
  53.     GrafPtr    savePort;
  54.     GetPort(&savePort);
  55.     SetPort(theWin);
  56.     InvalRect(&theWin->portRect);
  57.     SetPort(savePort);
  58. }
  59.  
  60. void DefaultHandleClick(WindowPtr theWin, Point where)
  61. {
  62. }
  63.  
  64. void DefaultDraw(WindowPtr theWin)
  65. {
  66. }
  67.  
  68.  
  69. /************************************************************************************
  70.  * Routines for maintaining floating windows.                        
  71.  *
  72.  ************************************************************************************/
  73.  
  74. WindowPtr FrontDocument(void)
  75. {
  76.     WindowPeek    theWin;
  77.     theWin = (WindowPeek) FrontWindow();
  78.     while (theWin && ((ObjectWindowPtr) theWin)->floating)
  79.         theWin = theWin->nextWindow;
  80.     if (theWin && !((ObjectWindowPtr) theWin)->floating)
  81.         return (WindowPtr) theWin;
  82.     else
  83.         return NULL;
  84. }
  85.  
  86. WindowPtr FrontFloating(void)
  87. {
  88.     WindowPeek    theWin;
  89.     theWin = (WindowPeek) FrontWindow();
  90.     while (theWin && !((ObjectWindowPtr) theWin)->floating)
  91.         theWin =  theWin->nextWindow;
  92.     if (theWin && ((ObjectWindowPtr) theWin)->floating)
  93.         return (WindowPtr) theWin;
  94.     else
  95.         return NULL;
  96. }
  97.  
  98. void SelectDocument(WindowPtr theWindow)
  99. {
  100.     WindowPeek    frontFloat;
  101.     frontFloat = (WindowPeek) FrontFloating();
  102.     if (frontFloat == NULL)
  103.         SelectWindow(theWindow);
  104.     else {
  105.         while ( frontFloat->nextWindow &&
  106.                 ((ObjectWindowPtr) frontFloat->nextWindow)->floating)
  107.             frontFloat = frontFloat->nextWindow;
  108.         SendBehind(theWindow, (WindowPtr) frontFloat);
  109.         HiliteWindow(theWindow,true);
  110.         CalcVisBehind((WindowPeek) FrontWindow(),((WindowPeek) theWindow)->strucRgn);
  111.         PaintOne((WindowPeek) theWindow,((WindowPeek) theWindow)->strucRgn);
  112.     }
  113. }
  114.  
  115. void SelectFloating(WindowPtr theWindow)
  116. {
  117.     SelectWindow(theWindow);
  118. }
  119.  
  120. void LocateWindows(void)
  121. {
  122. //    WindowPtr    frontDoc;
  123. //    if ((frontDoc = FrontDocument()) != NULL) {
  124. //        SelectDocument(frontDoc);
  125. //    }
  126. }